<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <img src="123.png" id="ims" width="300" height="380"><br>
    <input type="button" value="开始" onclick="start()">
    <input type="button" value="结束" onclick="end()">
    <script>
        function start(){
            flag=setInterval(bian,50);
        }
        function end(){
            clearInterval(flag);
        }
        function bian()
        {
            var arr=["123.png","456.png","789.png"];
            //定义随机数
            //Math.floor的作用是向下取整
            //Math.random的作用是生成[0,)之间的随机数
            var i= Math.floor(Math.random()*arr.length);
            document.getElementById("ims").src=arr[i];
        }
    
    
    </script>
</body>

</html>